import dayjs from 'dayjs';

export const getBuyDataLocalKey = (code: string) => {
  return `fundsCode${code}`;
};

export function isHoliday(date: {
  year: () => any;
  month: () => number;
  date: () => any;
  day: () => number;
}) {
  const year = date.year();
  const month = date.month() + 1;
  const day = date.date();

  // 判断是否为中国传统节日
  if (month === 1 && day === 1) return true; // 元旦
  if (month === 2 && [4, 5, 6, 7, 8, 9, 10].includes(day)) return true; // 春节
  if (month === 4 && day === 4) return true; // 清明节
  if (month === 5 && [1, 2, 3, 4, 5, 6, 7].includes(day)) return true; // 劳动节
  if (month === 6 && [14, 15, 16].includes(day)) return true; // 端午节
  if (month === 9 && [19, 20, 21].includes(day)) return true; // 中秋节
  if (month === 10 && [1, 2, 3, 4, 5, 6, 7].includes(day)) return true; // 国庆节

  // 判断是否为周末
  if ([0, 6].includes(date.day())) return true;

  return false;
}

export const dayFormatter = (time: number) => {
  return time ? dayjs(time)?.format('YYYY-MM-DD') : '暂无';
};


